package com.tjetc.service.impl;

import com.tjetc.dao.DepartmentDao;
import com.tjetc.dao.RoomDao;
import com.tjetc.dao.impl.DepartmentDaoImpl;
import com.tjetc.dao.impl.RoomDaoImpl;
import com.tjetc.domain.Room;
import com.tjetc.service.RoomService;
import com.tjetc.utils.PageInfo;

import java.sql.SQLException;
import java.util.List;

public class RoomServiceImpl implements RoomService {
    private RoomDao roomDao=new RoomDaoImpl();
    private DepartmentDao departmentDao=new DepartmentDaoImpl();
    @Override
    public int getCount(String number) {
        try {
            return roomDao.getCount(number);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Room> list(String number, PageInfo<Room> pageInfo) {
        try {
            List<Room> list=roomDao.list(number,pageInfo);
            for (Room room : list) {
                room.setDepartment(departmentDao.getById(room.getDepid()));
            }
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Room findByNumber(String number) {
        try {
            return roomDao.findByNumber(number);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean add(Room room) {
        try {
            return roomDao.add(room)>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean update(Room room) {
        try {
            return roomDao.update(room)>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean del(int id) {
        try {
            return roomDao.del(id)>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public List<Room> list1() {
        try {
            return roomDao.list1();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Room findById(int roomid) {
        try {
            return roomDao.findById(roomid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
